<%@ Page Title="" Language="C#" MasterPageFile="~/ABM.Master" AutoEventWireup="true"
    CodeBehind="Seguimiento3.aspx.cs" Inherits="EncuentraWEB.Formulario_web19" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .style3
        {
            width: 77px;
            height: 34px;
        }
        .style4
        {
            height: 542px;
            width: 77px;
        }
        .style6
        {
            width: 873px;
            height: 34px;
        }
        .style7
        {
            height: 542px;
            width: 873px;
        }
        .style8
        {
            width: 1068px;
            height: 34px;
        }
    </style>

    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAW_vO5gTGD3WOujJaX3VyVhS3OLMgfgRH-fiS7wt-9Lvh34X5rRRKlLui90JJl0aYGoyZqjDDIJ0D1Q"
        type="text/javascript"></script>

    <script type="text/javascript">
        var map;
        var snapToRoute;
        var routeOverlay;
        var lookingGlass;
        var puntos = new Array();
        var count = 0;


        function PABLO() {

            if (GBrowserIsCompatible()) {
                map = new GMap2(document.getElementById("map4"));
                map.setCenter(new GLatLng(-32.936135, -60.674550), 15);
                //map.setMapType(G_NORMAL_MAP);
                map.setMapType(G_HYBRID_MAP);
                map.addControl(new GLargeMapControl());
                map.addControl(new GOverviewMapControl());
                puntitos = 0;
                punLat = 0;
                punLong = 0;
                count = 0;
                cargarxml();

                // GEvent.addListener(map, "click", tratamiento_clic);
                
                setInterval(cargarxml, 20000);
            }
        }
        //localhost:49768



        function web(c) {
            EjecuarWebServices('http://localhost:49768/ServiceEncuentra.asmx', 'GetSelectObjectXML', c);
           
        }

        function Coches() {
            var filtro="";
            var tree = document.getElementById("ctl00_ContentPlaceHolder1_TreeView1");
                var tables = tree.getElementsByTagName('table');
                if (tables) {
                    for (var i = 0, j = tables.length; i < j; i++) {
                        var childTreeLevel = tables[i].rows[0].cells.length;
                        var cell = tables[i].rows[0].cells[childTreeLevel - 1];
                        
                            var inputs = cell.getElementsByTagName("INPUT");
                            if (inputs[0].checked) {
                            
                                links = tables[i].getElementsByTagName('a');
                                if (links) {
                                    for (var x = 0, y = links.length; x < y; x++) {

                                        if (links[x].firstChild.nodeName.toLowerCase() == '#text') {
                                             var result = links[x].firstChild.parentNode.href.toLowerCase().indexOf("coc");
                                            if (result != -1) {
                                                var coche = links[x].firstChild.parentNode.href.substring(result + 3)
                                                result = coche.indexOf("')");
                                                coche = coche.substring(1, result - 1);
                                                filtro = filtro + coche + ","
                                            }
                                        }
                                    }
                            }
                        }
                    }
                }

                return filtro;
        }


        function cargarxml() {
            var c = Coches();
            web(c);
            map.clearOverlays();
            if (document.getElementById("Hidden1").value.length > 0) {
                var xmlDoc = GXml.parse(document.getElementById("Hidden1").value);
                var posicion = xmlDoc.documentElement.getElementsByTagName("marca");
                for (var i = 0; i < posicion.length; i++) {
                    var lat = parseFloat(posicion[i].getAttribute("decLatitud"));
                    var lng = parseFloat(posicion[i].getAttribute("decLongitud"));
                    var punto = new GLatLng(lat, lng);
                    var equipo = posicion[i].getAttribute("varIdButton");
                    var Hora = posicion[i].getAttribute("datUltimoDato");
                    var html = posicion[i].getAttribute("html");
                    CrearMarca(punto, equipo + " - " + Hora,html);
                }
            }
        }

        function CrearMarca(punto, Descripcion,html) {
            var EtpIcon = new GIcon(G_DEFAULT_ICON);
            EtpIcon.image = "/Imagenes/busazul1.png";
            EtpIcon.iconSize = new GSize(21, 32);
         	EtpIcon.shadowSize = new GSize(0, 0);
            markerOptions = {icon:EtpIcon, title: Descripcion }
            var pos = new GMarker(punto, markerOptions);
            GEvent.addListener(pos, "click", function() {
                pos.openInfoWindowHtml(html);
            });
            map.addOverlay(pos);
        }

    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"  runat="server">

    <table >
        <tr>
            <td style="width: 10%" bgcolor="#CEC5DA">
                <input id="Hidden1" type="hidden" />
                <asp:Image ID="Image2" runat="server" Height="100%" ImageUrl="~/Imagenes/capas.jpg"
                    Width="100%" />
            </td>
            <td bgcolor="#CEC5DA" class="style8" valign="middle">

                <asp:ScriptManager ID="ScriptManager1" runat="server">
                <Scripts>
                        <asp:ScriptReference Path="WebServiceProxy.js" />
                    </Scripts>
                </asp:ScriptManager>
                <asp:Panel ID="Panel2" runat="server">
                    <asp:Label ID="Label13" runat="server" Text="Seguimiento de flota en mapa" CssClass="Titulos"></asp:Label>
                </asp:Panel>
            </td>
            <td bgcolor="#CEC5DA" width="7%">
                <asp:Image ID="Image3" runat="server" Height="42px" ImageUrl="~/Imagenes/NOVACORE.gif"
                    Style="margin-left: 0px" Width="124px" />
            </td>
        </tr>
        <tr   style=" height: 100%">
            <td valign="top">
                <table cellpadding="3">
                    <tr >
                        <td Height="50%">
                            <asp:Panel ID="Panel1" runat="server"  BackColor="Gray">
                                <asp:TreeView ID="TreeView1" runat="server" CssClass="treeview" ShowCheckBoxes="All"
                                    ForeColor="White" Width="142px"  ShowExpandCollapse="False">
                                </asp:TreeView>
                            </asp:Panel>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:CheckBox ID="chkPosicion"  CssClass="label" runat="server" 
                                Text="Posiciones " />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:CheckBox ID="chkEtapa"  CssClass="label" runat="server" Text="Etapas" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:CheckBox ID="chkInspeccion"   CssClass="label" runat="server" Text="Inspecciones" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:CheckBox ID="chkCheckPoint"   CssClass="label" runat="server" Text="Puntos de Control" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:HyperLink ID="HyperLink1" runat="server" CssClass="label" Font-Bold="True" NavigateUrl="~/Principal.aspx">Inicio</asp:HyperLink>
                        </td>
                    </tr>
                </table>
            </td>
            <td class="style7" colspan="2">
                <div id="map4" style="width: 100%; height: 100%">
                </div>
                &nbsp;
            </td>
        </tr>
    </table>
   
</asp:Content>
